﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBHelper;
using BusinessLayer.RegInfo.Entities;
using System.Data.SqlClient;
using System.Data;


namespace BusinessLayer.RegInfo
{
    public class LogActionBL
    {
        private readonly DbHelper _db;

        public LogActionBL()
        {
            _db = new DbHelper(new DbConfig().DbRegInfoConnectionString);
        }

        public List<AdminLogAction> GetAll()
        {
            var oCommand = new SqlCommand(Common.Constants.StoredProcedures.GetAllAdminLogActions) { CommandType = CommandType.StoredProcedure };

            var list = _db.GetList<AdminLogAction>(oCommand);
            return list;
        }
        public int CreateLogAction(AdminLogAction action)
        {
            int result = -1;
            try
            {
                var oCommand = new SqlCommand(Common.Constants.StoredProcedures.InsertAdminLogAction) { CommandType = CommandType.StoredProcedure };
                oCommand.Parameters.Add(new SqlParameter("@Action", action.Action));
                oCommand.Parameters.Add(new SqlParameter("@Description", action.Description));
                oCommand.Parameters.Add(new SqlParameter("@IPAddress", action.IPAddress));
                oCommand.Parameters.Add(new SqlParameter("@Time", action.Time));
                oCommand.Parameters.Add(new SqlParameter("@UserID", action.UserID));
                oCommand.Parameters.Add(new SqlParameter("@UserName", action.UserName));


                result = _db.ExecuteNonQuery(oCommand);
                return result;
            }
            catch (Exception ex)
            {

            }
            return result;


        }
       
    }
}
